<?php

namespace app\controllers;

use app\kit\Common;
use app\services\LampUserService;
use Yii;
use yii\data\ArrayDataProvider;
use yii\db\Query;
use yii\web\Response;

class ModelCacheController extends BaseController
{
    public function actionIndex()
    {
        $params = Yii::$app->request->get();
        $page = (int)($params['page'] ?? 1);
        $pageSize = (int)($params['per-page'] ?? 5);

        // 清理无关参数
        unset($params['page'], $params['per-page'], $params['r']);

        // 调用Service
        $userService = new LampUserService();
        $result = $userService->search($params, $page, $pageSize);

        $data = [
            'list' => $result['items'],
            'pagination' => [
                'pageSize' => $pageSize,
                'totalCount' => $result['totalCount'],
            ],
        ];
        return $data;
    }

    public function actionInfos()
    {
        $redis = Yii::$app->redis;
        $data[] = $redis->set('appname', 'yii');
        $data[] = $redis->get('appname');
        // 检查Redis扩展信息
        echo "Redis扩展版本: " . phpversion('redis');
        echo "Redis支持管道: " . (defined('Redis::PIPELINE') ? '是' : '否');
        return $data;
    }

}